package ar.edu.uba.fi.jmit.aspecter.testUtils;

import java.util.LinkedList;
import java.util.List;

import javassist.ClassPool;
import javassist.CtClass;
import ar.edu.uba.fi.jmit.aspecter.core.AdviceWeaver;
import ar.edu.uba.fi.jmit.aspecter.core.exception.AspecterException;

public class SpyAdviceWeaver extends AdviceWeaver {
	
	private List<CtClass> advicedClasses = new LinkedList<CtClass>();

	public SpyAdviceWeaver(ClassPool pool) {
		super(pool, "./src/test/java");
	}
	
	public SpyAdviceWeaver() {
		this(ClassPool.getDefault());
	}
	
	public CtClass applyAdvice(CtClass ctClass) throws AspecterException {
		logger.debug("Applying advice to class " + ctClass.getName());
		advicedClasses.add(ctClass);
		return ctClass;
	}
	
	public List<CtClass> getAdvicedClasses() {
		return this.advicedClasses;
	}
	
	public boolean advicedClass(String className) {
		for(CtClass ctClass:advicedClasses) {
			if(className.equals(ctClass.getName())) {
				return true;
			}
		}
		return false;
	}

}
